package com.ztjy.statis.controller;

import com.github.pagehelper.PageInfo;
import com.ztjy.bean.City;
import com.ztjy.bean.CkStatis;
import com.ztjy.bean.RkStatis;
import com.ztjy.bean.Users;
import com.ztjy.statis.biz.RkStatisBiz;
import com.ztjy.sys.biz.AreaBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/statis/rk")
public class RkStatisController {
    @Autowired
    private RkStatisBiz rkbiz;
    @Autowired
    private AreaBiz abiz;

    @RequestMapping("/allrkstatis")
    public String findAllRkStatis(Model model, RkStatis rkStatis, @RequestParam(defaultValue = "1",value = "pageno")Integer pageNo, HttpSession session){
        Integer pageSize=6;
        Users user=(Users) session.getAttribute("currUser");
        Integer jobId = user.getJobId();
        if (jobId==6||jobId==1){
            PageInfo<RkStatis> allRkStatis = rkbiz.findAllRkStatis(rkStatis, pageNo, pageSize);
            model.addAttribute("rkstatisinfo",allRkStatis);
            if(rkStatis!=null){
                Integer cityId = rkStatis.getCityId();
                City city = abiz.findCityById(cityId);
                rkStatis.setCity(city);
            }
            model.addAttribute("rkStatis",rkStatis);
            return "forward:/statis/stock/stockStatis.html";
        }else{
            return "";
        }
    }

    @RequestMapping("/rkview")
    public String findRkView(Model model,Integer id,@RequestParam(defaultValue = "1",value = "pageno")Integer pageNo){
        Integer pageSize=6;
        PageInfo<RkStatis> rkstatisById = rkbiz.findRkstatisById(id, pageNo, pageSize);
        model.addAttribute("allrkbywid",rkstatisById);
        model.addAttribute("id",id);
        return "forward:/statis/stock/stockView.html";
    }

    @RequestMapping("/tiaozhuang")
    @ResponseBody
    public List<RkStatis> findtiaozhuangtu(){
        List<RkStatis> findtiaozhuang = rkbiz.findtiaozhuang();
        return findtiaozhuang;
    }
}
